/*
 * Copyright (C) 2010-2012 Susanta Tewari
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package genomemap.cef.command;

import cef.command.Command;
import cef.command.CommandException;
import genomemap.cef.event.DrawContigMap_Evt;
import genomemap.data.KSA00Data;
import genomemap.map.ContigMap;
import genomemap.map.FullContigMap;
import genomemap.map.MinimalContigMap;
import genomemap.map.ProbeMap;

import javax.swing.*;

/**
 * @author Susanta Tewari
 * @history Created on Sep 5, 2012.
 */
public class DrawContigMap_Cmd extends Command<DrawContigMap_Evt> {

    /** Field description */
    private JScrollPane mapPane;

    public DrawContigMap_Cmd(final DrawContigMap_Evt event) {
        super(event);
    }

    @Override
    public void executeImpl() throws CommandException, InterruptedException {

        final KSA00Data data                          = getEvent().getData();
        final ProbeMap probeMap                       = new ProbeMap(data, "probe-map");
        final DrawContigMap_Evt.ContigMapType mapType = getEvent().getContigMapType();


        // create full contig map
        ContigMap contigMap = null;

        switch (mapType) {

            case FULL :
                contigMap = new FullContigMap(probeMap);

                break;

            case MINIMAL :
                contigMap = new MinimalContigMap(probeMap);

                break;

            default :
                throw new CommandException("unexpected contig type");
        }


        // create component
        final JTextArea mapArea = new JTextArea(contigMap.toString());

        mapArea.setEditable(false);


        // will only change size to 12pt
        mapArea.setFont(new java.awt.Font("Monospaced", 0, 13));

        mapPane = new JScrollPane(mapArea);
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public JComponent getContigMap() {

        checkCmdFinished();

        return mapPane;
    }
}
